#ifndef WIDGET_H
#define WIDGET_H

#include "dfsthread.h"
#include <QPushButton>
#include <QTextEdit>
#include <QLineEdit>

QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();
    void mousePressEvent(QMouseEvent* event);
private:
    struct Unit : public QPushButton{
        Unit(QWidget *parent=nullptr): QPushButton(parent){}
        int r = -1, c = -1;
        int move_range = 5;
        MapSquare::UNIT_TYPE unit_type;
    };
    void initUnit(Unit* unit, MapSquare::UNIT_TYPE unit_type);
    void moveUnit(Unit* unit, int r, int c);
    void connectUnit(Unit* &unit);

private:
    void initUI();
    void connectUI();
    void updateTextEdit();
    void updateMapFromTextEdit();
    void initMap();
    void resetMap();
    bool dfsThreadIsRunning();

private:
    DfsThread dfsThread;
    int r_map = 10, c_map = 10;
    QVector<QVector<MapSquare*>> map;
    Unit *src, *dst;
private:
    QPushButton *pushButton0, *pushButton1, *pushButton2, *pushButton3, *pushButton4, *pushButton5,
                *pushButton6, *pushButton7, *pushButton8;
    QTextEdit *textEdit;
    QLineEdit *lineEdit_setsrcx;
    QLineEdit *lineEdit_setsrcy;
    QLineEdit *lineEdit_setdstx;
    QLineEdit *lineEdit_setdsty;
    QLineEdit *lineEdit_set_range;


private:
    Ui::Widget *ui;
};
#endif // WIDGET_H
